package com.irdstudio.efp.batch.service.impl.hjwp;

import com.irdstudio.efp.console.common.psd.PsdConstantSet;
import com.irdstudio.efp.loan.service.vo.AccLoanVO;
import com.irdstudio.efp.nls.common.constant.PrdInfoEnum;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * 批扣同步公共类
 */
public class SyncUtil {
    /**
     * 根据互金传递的产品类型转换成网贷的产品编码 如果新增了产品需要在这里添加
     *
     * @param prdType
     * @return
     */
    public static String changPrdCodeByType(String prdType) {
        //普税贷款
        if (prdType.equals("10001002")) {
            return PsdConstantSet.prdId;
        }
        return prdType;
    }

    /**
     * 校验时间
     * @param bizeDateStr
     * @param openDay
     * @return
     */
    public static boolean checkDate(String bizeDateStr,String openDay) {
        //批次时间
        LocalDate openDayDate = LocalDate.parse(openDay, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        //借据创建时间
        LocalDate bizeDate = LocalDate.parse(bizeDateStr, bizeDateStr.length()>10?DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"):DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        if (bizeDate.until(openDayDate, ChronoUnit.DAYS) > 0) {
            //借据的账务日期在当前的openday时间之前
            return true;
        }
        return false;
    }

}
